#!/bin/bash

. functions.sh

sudo chown -LRf vagrant.vagrant /var/lib/php/session

#Copy Nginx ssl files

# Copy the api.json file to where platform will find it
sudo \cp $SOURCE_ROOT/vagrant/api.json /etc/foxitcloud/

Str=`echo ${HOSTNAME}|awk -F '.' '{print $3}'`
# vagrant,demo env

if [[ ${Str} = 'foxitcloud' ]] ; then
        sudo sed -i "s/vagrant./$PC_ENV./g" /etc/nginx/vhost/vhost-local.conf
        sudo sed -i "s/vagrant./$PC_ENV./g" /etc/foxitcloud/api.json
        sudo sed -i "s/vagrant\./$PC_ENV\./g" /etc/nginx/vhost/phantom-online.conf
else
# pro env
        sudo sed -i "s/.vagrant././g" /etc/nginx/vhost/vhost-local.conf
        sudo sed -i "s/.demo2././g" /etc/nginx/vhost/storage-demo2.conf
        sudo sed -i "s/v\.//g" /etc/nginx/vhost/vhost-local.conf
fi
if [ -f $SOURCE_ROOT/webapp/connectedpdfapp/web/dll-config/1.0/cpdfApi.json ]; then

        sudo sed -i "s/vagrant./$PC_ENV./g" $SOURCE_ROOT/webapp/connectedpdfapp/web/dll-config/1.0/cpdfApi.json
fi

if [ -f $SOURCE_ROOT/webapp/connectedpdfapp/web/dll-config/2.0/cpdfApi.json ]; then

        sudo sed -i "s/vagrant./$PC_ENV./g" $SOURCE_ROOT/webapp/connectedpdfapp/web/dll-config/2.0/cpdfApi.json
fi

if  lsmod | grep -q vboxsf ; then
sed -i '/sendfile/s/on/off/' /etc/nginx/nginx.conf
fi

# Restart Nginx.
echo "Restarting Nginx"

#if [[ "$YUM_SYS" =~ ^6\..* ]]; then
#sudo service nginx restart
#fi

#if [[ "$YUM_SYS" =~ ^7\..* ]]; then
#sudo systemctl restart nginx
#fi



